using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Pool;

public class BasePool : MonoBehaviour
{
    [SerializeField] private GameObject PrefabObject;
    [HideInInspector] public ObjectPool<GameObject> Pool;

    protected void Init()
    {
        Pool = new ObjectPool<GameObject>(CreateItem, GetItem, ReleaseItem, DestroyItem);
    }

    private GameObject CreateItem() {
        GameObject obj = Instantiate(PrefabObject);
        obj.transform.SetParent(transform);
        obj.SetActive(false);
        return obj;
    }

    private void GetItem(GameObject item) {
        item.SetActive(true);
    }

    private void ReleaseItem(GameObject item) {
        item.SetActive(false);
    }

    private void DestroyItem(GameObject item)
    {
        Destroy(item);
    }
}
